package com.itheima.edu.info.manager.ceshi;

import org.apache.log4j.net.SocketServer;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

import static java.lang.String.*;

public class SocketServerTest {
    public static void main(String[] args) throws IOException {
        //创建服务器并监听4396端口
        ServerSocket ss=new ServerSocket(4396);
        Socket accept = ss.accept();
      //  Socket accept1 = ss.accept();
        //向客户端发送数据,并换行,刷新,且告诉客户端数据发送完毕
        BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));

        bw.write("欢迎光临！请上传文件(文本文件)！");
        bw.newLine();
        bw.flush();
       //bw.close();
       // accept.shutdownOutput();
        BufferedReader br=new BufferedReader(new InputStreamReader(accept.getInputStream()));
        BufferedWriter bw1=new BufferedWriter(new FileWriter("D:\\jinjie\\实验\\"+ UUID.randomUUID()+".txt"));
        int a;
       // byte []arr=new byte[1024];
        while ((a=  br.read())!=-1){

            if("操".equals(String.valueOf((char) a))){
                a='*';
            }
            bw1.write(a);
            bw1.flush();
        }
        BufferedWriter bw2=new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw2.write("上传成功");
        accept.shutdownOutput();
        bw2.close();
        bw1.close();
        ss.close();

    }
    }




